{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "将test.jsonl进行处理，转换成new_train.jsonl和new_test.jsonl\n",
    "\n",
    "也就是拆分为训练集  和  测试集\n",
    "\n",
    "一般测试集，选所有数据的 90%\n",
    "\n",
    "测试集，取10%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import pandas as pd\n",
    "import os\n",
    "\n",
    "def dataset_jsonl_transfer(origin_path, new_path):\n",
    "  \"\"\"\n",
    "  将原始数据集转换为大模型微调所需数据格式的新数据集\n",
    "  \"\"\"\n",
    "  messages = []\n",
    "  # 读取旧的JSONL文件\n",
    "  with open(origin_path, \"r\", encoding=\"utf-8\") as file:\n",
    "    print(\"验证是否开始执行===\")\n",
    "    for line in file:\n",
    "      # 解析每一行的json数据\n",
    "      data = json.loads(line.strip())\n",
    "      input_text = data[\"text\"]\n",
    "      entities = data[\"entities\"]\n",
    "      match_names = [\"地点\", \"人名\", \"地理实体\", \"组织\"]\n",
    "      \n",
    "      entity_sentence = \"\"\n",
    "      for entity in entities:\n",
    "        entity_json = dict(entity)\n",
    "        # print(f\"entity_json: {entity_json}\")\n",
    "        entity_text = entity_json[\"entity_text\"]\n",
    "        entity_names = entity_json[\"entity_names\"]\n",
    "        for name in entity_names:\n",
    "          if name in match_names:\n",
    "            entity_label = name\n",
    "            break\n",
    "        \n",
    "        entity_sentence += f\"\"\"{{\"entity_text\": \"{entity_text}\", \"entity_label\": \"{entity_label}\"}}\"\"\"\n",
    "      \n",
    "      if entity_sentence == \"\":\n",
    "        entity_sentence = \"没有找到任何实体\"\n",
    "      \n",
    "      message = {\n",
    "        \"instruction\": \"\"\"你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 实体. 以 json 格式输出, 如 {\"entity_text\": \"南京\", \"entity_label\": \"地理实体\"} 注意: 1. 输出的每一行都必须是正确的 json 字符串. 2. 找不到任何实体时, 输出\"没有找到任何实体\". \"\"\",\n",
    "        \"input\": f\"文本:{input_text}\",\n",
    "        \"output\": entity_sentence,\n",
    "      }\n",
    "      \n",
    "      messages.append(message)\n",
    "\n",
    "  # 保存重构后的JSONL文件\n",
    "  with open(new_path, \"w\", encoding=\"utf-8\") as file:\n",
    "    for message in messages:\n",
    "      file.write(json.dumps(message, ensure_ascii=False) + \"\\n\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加载原始数据集， 并调用 dataset_jsonl_transfer 函数进行转换\n",
    "train_dataset_path = \"test.jsonl\"\n",
    "train_jsonl_new_path = \"test_train.jsonl\"\n",
    "\n",
    "if not os.path.exists(train_jsonl_new_path):\n",
    "  dataset_jsonl_transfer(train_dataset_path, train_jsonl_new_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Cannot take a larger sample than population when 'replace=False'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[8], line 5\u001b[0m\n\u001b[0;32m      3\u001b[0m total_df \u001b[39m=\u001b[39m pd\u001b[39m.\u001b[39mread_json(train_jsonl_new_path, lines\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n\u001b[0;32m      4\u001b[0m train_df \u001b[39m=\u001b[39m total_df[\u001b[39mint\u001b[39m(\u001b[39mlen\u001b[39m(total_df) \u001b[39m*\u001b[39m \u001b[39m0.1\u001b[39m):]  \u001b[39m# 取90%的数据做训练集\u001b[39;00m\n\u001b[1;32m----> 5\u001b[0m test_df \u001b[39m=\u001b[39m total_df[:\u001b[39mint\u001b[39;49m(\u001b[39mlen\u001b[39;49m(total_df) \u001b[39m*\u001b[39;49m \u001b[39m0.1\u001b[39;49m)]\u001b[39m.\u001b[39;49msample(n\u001b[39m=\u001b[39;49m\u001b[39m5\u001b[39;49m)  \u001b[39m# 随机取10%的数据中的5条做测试集\u001b[39;00m\n",
      "File \u001b[1;32md:\\conda\\envs\\tuning_env\\lib\\site-packages\\pandas\\core\\generic.py:6140\u001b[0m, in \u001b[0;36mNDFrame.sample\u001b[1;34m(self, n, frac, replace, weights, random_state, axis, ignore_index)\u001b[0m\n\u001b[0;32m   6137\u001b[0m \u001b[39mif\u001b[39;00m weights \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m   6138\u001b[0m     weights \u001b[39m=\u001b[39m sample\u001b[39m.\u001b[39mpreprocess_weights(\u001b[39mself\u001b[39m, weights, axis)\n\u001b[1;32m-> 6140\u001b[0m sampled_indices \u001b[39m=\u001b[39m sample\u001b[39m.\u001b[39;49msample(obj_len, size, replace, weights, rs)\n\u001b[0;32m   6141\u001b[0m result \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mtake(sampled_indices, axis\u001b[39m=\u001b[39maxis)\n\u001b[0;32m   6143\u001b[0m \u001b[39mif\u001b[39;00m ignore_index:\n",
      "File \u001b[1;32md:\\conda\\envs\\tuning_env\\lib\\site-packages\\pandas\\core\\sample.py:152\u001b[0m, in \u001b[0;36msample\u001b[1;34m(obj_len, size, replace, weights, random_state)\u001b[0m\n\u001b[0;32m    149\u001b[0m     \u001b[39melse\u001b[39;00m:\n\u001b[0;32m    150\u001b[0m         \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mInvalid weights: weights sum to zero\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m--> 152\u001b[0m \u001b[39mreturn\u001b[39;00m random_state\u001b[39m.\u001b[39;49mchoice(obj_len, size\u001b[39m=\u001b[39;49msize, replace\u001b[39m=\u001b[39;49mreplace, p\u001b[39m=\u001b[39;49mweights)\u001b[39m.\u001b[39mastype(\n\u001b[0;32m    153\u001b[0m     np\u001b[39m.\u001b[39mintp, copy\u001b[39m=\u001b[39m\u001b[39mFalse\u001b[39;00m\n\u001b[0;32m    154\u001b[0m )\n",
      "File \u001b[1;32mnumpy/random/mtrand.pyx:1020\u001b[0m, in \u001b[0;36mnumpy.random.mtrand.RandomState.choice\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: Cannot take a larger sample than population when 'replace=False'"
     ]
    }
   ],
   "source": [
    "# 拆分  训练集 和  数据集\n",
    "\n",
    "total_df = pd.read_json(train_jsonl_new_path, lines=True)\n",
    "train_df = total_df[int(len(total_df) * 0.1):]  # 取90%的数据做训练集\n",
    "# test_df = total_df[:int(len(total_df) * 0.1)].sample(n=20)  # 随机取10%的数据中的20条做测试集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>input</th>\n",
       "      <th>output</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:菲律宾总统埃斯特拉达２号透过马尼拉当地电台宣布说，在仍遭到激进的回教阿卜沙耶夫组织羁押...</td>\n",
       "      <td>{\"entity_text\": \"菲律宾\", \"entity_label\": \"地理实体\"}...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:获救的人质为以前电视布道家阿美达为首的基督教传教士。</td>\n",
       "      <td>{\"entity_text\": \"阿美达\", \"entity_label\": \"人名\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:阿美达在７月份前往和落岛为遭到绑架、狭持的人质祷告。</td>\n",
       "      <td>{\"entity_text\": \"阿美达\", \"entity_label\": \"人名\"}{\"...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:埃斯特拉达２号接受菲律宾一家电台访问时说，三军参谋总长雷耶丝打电话向他报告说，阿美达和...</td>\n",
       "      <td>{\"entity_text\": \"埃斯特拉达\", \"entity_label\": \"人名\"}...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:继续是重要的国际新闻。</td>\n",
       "      <td>没有找到任何实体</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:首先我们先来关心南斯拉夫总统大选的状况。</td>\n",
       "      <td>{\"entity_text\": \"南斯拉夫\", \"entity_label\": \"地理实体\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:南斯拉夫独立的ｂ２９２电台５号报导说，南斯拉夫宪法法庭主席塞尔迪克指出，南斯拉夫引发争...</td>\n",
       "      <td>{\"entity_text\": \"南斯拉夫\", \"entity_label\": \"地理实体\"...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:报导引述自由欧洲电台的消息指出，塞尔迪尔表示南国总统选举第一回合无效，选举必须要重新举...</td>\n",
       "      <td>{\"entity_text\": \"塞尔迪尔\", \"entity_label\": \"人名\"}{...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:而英国外交部５号则对南国宪法法庭裁决南国将重新举行总统选举表示谴责。</td>\n",
       "      <td>{\"entity_text\": \"英国\", \"entity_label\": \"地理实体\"}{...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:英国外交部在声明中表示，南国宪法法庭宣布南国总统选举无效，使米洛舍维奇仍然留任的措施令...</td>\n",
       "      <td>{\"entity_text\": \"英国\", \"entity_label\": \"地理实体\"}{...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         instruction  \\\n",
       "0  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "1  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "2  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "3  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "4  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "5  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "6  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "7  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "8  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "9  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "\n",
       "                                               input  \\\n",
       "0  文本:菲律宾总统埃斯特拉达２号透过马尼拉当地电台宣布说，在仍遭到激进的回教阿卜沙耶夫组织羁押...   \n",
       "1                      文本:获救的人质为以前电视布道家阿美达为首的基督教传教士。   \n",
       "2                      文本:阿美达在７月份前往和落岛为遭到绑架、狭持的人质祷告。   \n",
       "3  文本:埃斯特拉达２号接受菲律宾一家电台访问时说，三军参谋总长雷耶丝打电话向他报告说，阿美达和...   \n",
       "4                                     文本:继续是重要的国际新闻。   \n",
       "5                            文本:首先我们先来关心南斯拉夫总统大选的状况。   \n",
       "6  文本:南斯拉夫独立的ｂ２９２电台５号报导说，南斯拉夫宪法法庭主席塞尔迪克指出，南斯拉夫引发争...   \n",
       "7  文本:报导引述自由欧洲电台的消息指出，塞尔迪尔表示南国总统选举第一回合无效，选举必须要重新举...   \n",
       "8              文本:而英国外交部５号则对南国宪法法庭裁决南国将重新举行总统选举表示谴责。   \n",
       "9  文本:英国外交部在声明中表示，南国宪法法庭宣布南国总统选举无效，使米洛舍维奇仍然留任的措施令...   \n",
       "\n",
       "                                              output  \n",
       "0  {\"entity_text\": \"菲律宾\", \"entity_label\": \"地理实体\"}...  \n",
       "1       {\"entity_text\": \"阿美达\", \"entity_label\": \"人名\"}  \n",
       "2  {\"entity_text\": \"阿美达\", \"entity_label\": \"人名\"}{\"...  \n",
       "3  {\"entity_text\": \"埃斯特拉达\", \"entity_label\": \"人名\"}...  \n",
       "4                                           没有找到任何实体  \n",
       "5    {\"entity_text\": \"南斯拉夫\", \"entity_label\": \"地理实体\"}  \n",
       "6  {\"entity_text\": \"南斯拉夫\", \"entity_label\": \"地理实体\"...  \n",
       "7  {\"entity_text\": \"塞尔迪尔\", \"entity_label\": \"人名\"}{...  \n",
       "8  {\"entity_text\": \"英国\", \"entity_label\": \"地理实体\"}{...  \n",
       "9  {\"entity_text\": \"英国\", \"entity_label\": \"地理实体\"}{...  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(total_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据量小的情况下，拆分\n",
    "# 直接使用比例抽样\n",
    "train_df_90 = total_df.sample(frac=0.9, random_state=42)  # 90% 训练集\n",
    "test_df_10 = total_df.drop(train_df.index)  # 剩下的10%作为测试集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>input</th>\n",
       "      <th>output</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:而英国外交部５号则对南国宪法法庭裁决南国将重新举行总统选举表示谴责。</td>\n",
       "      <td>{\"entity_text\": \"英国\", \"entity_label\": \"地理实体\"}{...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:获救的人质为以前电视布道家阿美达为首的基督教传教士。</td>\n",
       "      <td>{\"entity_text\": \"阿美达\", \"entity_label\": \"人名\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:首先我们先来关心南斯拉夫总统大选的状况。</td>\n",
       "      <td>{\"entity_text\": \"南斯拉夫\", \"entity_label\": \"地理实体\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:菲律宾总统埃斯特拉达２号透过马尼拉当地电台宣布说，在仍遭到激进的回教阿卜沙耶夫组织羁押...</td>\n",
       "      <td>{\"entity_text\": \"菲律宾\", \"entity_label\": \"地理实体\"}...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:报导引述自由欧洲电台的消息指出，塞尔迪尔表示南国总统选举第一回合无效，选举必须要重新举...</td>\n",
       "      <td>{\"entity_text\": \"塞尔迪尔\", \"entity_label\": \"人名\"}{...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:阿美达在７月份前往和落岛为遭到绑架、狭持的人质祷告。</td>\n",
       "      <td>{\"entity_text\": \"阿美达\", \"entity_label\": \"人名\"}{\"...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:英国外交部在声明中表示，南国宪法法庭宣布南国总统选举无效，使米洛舍维奇仍然留任的措施令...</td>\n",
       "      <td>{\"entity_text\": \"英国\", \"entity_label\": \"地理实体\"}{...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:继续是重要的国际新闻。</td>\n",
       "      <td>没有找到任何实体</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:埃斯特拉达２号接受菲律宾一家电台访问时说，三军参谋总长雷耶丝打电话向他报告说，阿美达和...</td>\n",
       "      <td>{\"entity_text\": \"埃斯特拉达\", \"entity_label\": \"人名\"}...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         instruction  \\\n",
       "8  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "1  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "5  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "0  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "7  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "2  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "9  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "4  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "3  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "\n",
       "                                               input  \\\n",
       "8              文本:而英国外交部５号则对南国宪法法庭裁决南国将重新举行总统选举表示谴责。   \n",
       "1                      文本:获救的人质为以前电视布道家阿美达为首的基督教传教士。   \n",
       "5                            文本:首先我们先来关心南斯拉夫总统大选的状况。   \n",
       "0  文本:菲律宾总统埃斯特拉达２号透过马尼拉当地电台宣布说，在仍遭到激进的回教阿卜沙耶夫组织羁押...   \n",
       "7  文本:报导引述自由欧洲电台的消息指出，塞尔迪尔表示南国总统选举第一回合无效，选举必须要重新举...   \n",
       "2                      文本:阿美达在７月份前往和落岛为遭到绑架、狭持的人质祷告。   \n",
       "9  文本:英国外交部在声明中表示，南国宪法法庭宣布南国总统选举无效，使米洛舍维奇仍然留任的措施令...   \n",
       "4                                     文本:继续是重要的国际新闻。   \n",
       "3  文本:埃斯特拉达２号接受菲律宾一家电台访问时说，三军参谋总长雷耶丝打电话向他报告说，阿美达和...   \n",
       "\n",
       "                                              output  \n",
       "8  {\"entity_text\": \"英国\", \"entity_label\": \"地理实体\"}{...  \n",
       "1       {\"entity_text\": \"阿美达\", \"entity_label\": \"人名\"}  \n",
       "5    {\"entity_text\": \"南斯拉夫\", \"entity_label\": \"地理实体\"}  \n",
       "0  {\"entity_text\": \"菲律宾\", \"entity_label\": \"地理实体\"}...  \n",
       "7  {\"entity_text\": \"塞尔迪尔\", \"entity_label\": \"人名\"}{...  \n",
       "2  {\"entity_text\": \"阿美达\", \"entity_label\": \"人名\"}{\"...  \n",
       "9  {\"entity_text\": \"英国\", \"entity_label\": \"地理实体\"}{...  \n",
       "4                                           没有找到任何实体  \n",
       "3  {\"entity_text\": \"埃斯特拉达\", \"entity_label\": \"人名\"}...  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_df_90"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>input</th>\n",
       "      <th>output</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...</td>\n",
       "      <td>文本:菲律宾总统埃斯特拉达２号透过马尼拉当地电台宣布说，在仍遭到激进的回教阿卜沙耶夫组织羁押...</td>\n",
       "      <td>{\"entity_text\": \"菲律宾\", \"entity_label\": \"地理实体\"}...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         instruction  \\\n",
       "0  你是一个文本实体识别领域的专家，你需要从给定的句子中提取 地点; 人名; 地理实体; 组织 ...   \n",
       "\n",
       "                                               input  \\\n",
       "0  文本:菲律宾总统埃斯特拉达２号透过马尼拉当地电台宣布说，在仍遭到激进的回教阿卜沙耶夫组织羁押...   \n",
       "\n",
       "                                              output  \n",
       "0  {\"entity_text\": \"菲律宾\", \"entity_label\": \"地理实体\"}...  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_df_10"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "tuning_env",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.18"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "5b5cfca19401015264b4741f08a5ab630bb44e69b46d09de08cfb7d2d4656fc3"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
